<?php
/**
 * 前台 信息服务中心
 *
 */
class EinfoservicesAction extends Action
{
	/**
	 * 网站统一配置
	 *
	 * @var unknown_type
	 */
	public $Config;
	
	/**
	 * 构造函数
	 *
	 */
	public function _initialize()
	{
		$Config = D('Config');
		$this->Config = $Config->find('config_id=1');
	}
	/**
	 * 供求信息列表
	 */
	public function GQ()
	{
		//获取所有的特色企业分类
	 	$Class = D('Ecategory');
	 	$C = $Class->findall();
	 	
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',1);
		$conditions->put('einfos_audit',array('EQ','Y'));
		
		$Info = D('Einfoservices');
		$count = $Info->count($conditions,'einfos_id');
		$listRows = 20;
		$fields = 'einfos_id,id,cid,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,einfos_audit,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Info->xfindall($conditions,$fields,'einfos_top desc,einfos_sort desc,einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		
		//To tpl
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->assign('Class',$C);
		$this->assign('Config',$this->Config);
		$this->display();
	}
	//人才互动
	public function Jobs()
	{
		//获取所有的特色企业分类
	 	$Class = D('Ecategory');
	 	$C = $Class->findall();
	 	
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',4);
		$conditions->put('einfos_audit',array('EQ','Y'));
		
		$Info = D('Einfoservices');
		$count = $Info->count($conditions,'einfos_id');
		$listRows = 20;
		$fields = 'einfos_id,id,cid,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,einfos_audit,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Info->xfindall($conditions,$fields,'einfos_top desc,einfos_sort desc,einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		
		//To tpl
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->assign('Class',$C);
		$this->assign('Config',$this->Config);
		$this->display();
	}
	//项目合作
	public function Hezuo()
	{
		//获取所有的特色企业分类
	 	$Class = D('Ecategory');
	 	$C = $Class->findall();
	 	
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',3);
		$conditions->put('einfos_audit',array('EQ','Y'));
		
		$Info = D('Einfoservices');
		$count = $Info->count($conditions,'einfos_id');
		$listRows = 20;
		$fields = 'einfos_id,id,cid,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,einfos_audit,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Info->xfindall($conditions,$fields,'einfos_top desc,einfos_sort desc,einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		
		//To tpl
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->assign('Class',$C);
		$this->assign('Config',$this->Config);
		$this->display();
	}
	/**
	 * 首页Ajax获取企业资讯
	 */
	public function GetZixun()
	{
		//获取企业资讯
		$Einfos = D('Einfoservices');
		$EnterpriseNews = $Einfos
							->where('cid=15 and einfos_audit=\'Y\'')
							->order('einfos_top desc,einfos_sort desc,einfos_id desc')
							->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
							->limit(15)
							->xfindall();
		$this->assign('EnterpriseNews',$EnterpriseNews);//企业资讯
		$this->display();
	}
	/**
	 * 获取供求信息
	 */
	public function GQShow()
	{
		$Input = Input::getInstance();
		$Input->filter('addslashes');
		//设置查询条件
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',array('EQ','1'));
		$conditions->put('einfos_audit',array('EQ','Y'));
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Services = D('Einfoservices');
		$count = $Services->count($conditions,'einfos_id');
		$listRows = 15;
		$fields = 'einfos_id,id,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Services->xfindall($conditions,$fields,'einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		unset($conditions);
		//获取企业信息
		//设置条件
		$conditions = new HashMap();
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Enterprise = D('Enterprise');
		$Enter = $Enterprise->where($conditions)->find();
		//组成模板 xxx@Index:Show
    	$UserTpl = $Enter['templates'] . '@Einfoservices:GQShow';
		//dump($list);
		//To tpl
		$this->assign('Enterprise',$Enter);
		$this->assign('enter_id',$Input->get('enter_id'));
		$this->assign('Config',$this->Config);
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->display($UserTpl);
	}
	//Ajax获取供应信息
	public function GetGongYing() {
		$conditions = array();
		$conditions['id'] = 5;
		$Infos = D('Einfoservices');
		$Content = $Infos->where($conditions)->findall();
		//To tpl
		$this->assign('GQ',$Content);
		$this->assign('class','供应');
		$this->display('Ajax');
	}
	//Ajax获取求购信息
	public function GetQiuGou() {
		$conditions = array();
		$conditions['id'] = 6;
		$Infos = D('Einfoservices');
		$Content = $Infos->where($conditions)->findall();
		//To tpl
		$this->assign('GQ',$Content);
		$this->assign('class','求购');
		$this->display('Ajax');
	}
	//Ajax获取招聘信息
	public function GetZhaoPin() {
		$Einfos = D('Einfoservices');
		//招聘
		$Jobs = $Einfos->where('id=13 and einfos_audit=\'Y\'')
						->order('einfos_top desc,einfos_sort desc,einfos_id desc')
						->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
						->limit(15)
						->xfindall();
		$this->assign('Jobs',$Jobs);
		$this->display('GetQiuZhi');
	}
	public function GetQiuZhi() {
		$Einfos = D('Einfoservices');
		//求职
		$Jobs = $Einfos->where('id=14 and einfos_audit=\'Y\'')
						->order('einfos_top desc,einfos_sort desc,einfos_id desc')
						->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
						->limit(15)
						->xfindall();
						
		$this->assign('Jobs',$Jobs);
		$this->display('GetQiuZhi');
	}
	//二手信息
	public function UsedShow()
	{
		$Input = Input::getInstance();
		$Input->filter('addslashes');
		//设置查询条件
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',array('EQ','2'));
		$conditions->put('einfos_audit',array('EQ','Y'));
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Services = D('Einfoservices');
		$count = $Services->count($conditions,'einfos_id');
		$listRows = 15;
		$fields = 'einfos_id,id,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Services->xfindall($conditions,$fields,'einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		unset($conditions);
		//获取企业信息
		//设置条件
		$conditions = new HashMap();
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Enterprise = D('Enterprise');
		$Enter = $Enterprise->where($conditions)->find();
		//组成模板 xxx@Index:Show
    	$UserTpl = $Enter['templates'] . '@Einfoservices:UsedShow';
		//dump($list);
		//To tpl
		$this->assign('Enterprise',$Enter);
		$this->assign('enter_id',$Input->get('enter_id'));
		$this->assign('Config',$this->Config);
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->display($UserTpl);
	}
	//项目合作
	public function ItemShow()
	{
		$Input = Input::getInstance();
		$Input->filter('addslashes');
		//设置查询条件
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',array('EQ','3'));
		$conditions->put('einfos_audit',array('EQ','Y'));
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Services = D('Einfoservices');
		$count = $Services->count($conditions,'einfos_id');
		$listRows = 15;
		$fields = 'einfos_id,id,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Services->xfindall($conditions,$fields,'einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		unset($conditions);
		//获取企业信息
		//设置条件
		$conditions = new HashMap();
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Enterprise = D('Enterprise');
		$Enter = $Enterprise->where($conditions)->find();
		//组成模板 xxx@Index:Show
    	$UserTpl = $Enter['templates'] . '@Einfoservices:ItemShow';
		//dump($list);
		//To tpl
		$this->assign('Enterprise',$Enter);
		$this->assign('enter_id',$Input->get('enter_id'));
		$this->assign('Config',$this->Config);
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->display($UserTpl);
	}
	//人才招聘
	public function JobsShow()
	{
		$Input = Input::getInstance();
		$Input->filter('addslashes');
		//设置查询条件
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',array('EQ','4'));
		$conditions->put('einfos_audit',array('EQ','Y'));
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Services = D('Einfoservices');
		$count = $Services->count($conditions,'einfos_id');
		$listRows = 15;
		$fields = 'einfos_id,id,title,created';
		import('ORG.Util.Page');
		$p = new Page($count,$listRows);
		$list = $Services->xfindall($conditions,$fields,'einfos_id desc',$p->firstRow.','.$p->listRows);
		$page = $p->show();
		unset($conditions);
		//获取企业信息
		//设置条件
		$conditions = new HashMap();
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Enterprise = D('Enterprise');
		$Enter = $Enterprise->where($conditions)->find();
		//组成模板 xxx@Index:Show
    	$UserTpl = $Enter['templates'] . '@Einfoservices:JobsShow';
		//dump($list);
		//To tpl
		$this->assign('Enterprise',$Enter);
		$this->assign('enter_id',$Input->get('enter_id'));
		$this->assign('Config',$this->Config);
		$this->assign('Infos',$list);
		$this->assign('page',$page);
		$this->display($UserTpl);
	}
	
	/**
	 * 获取单挑信息内容
	 */
	public function DS()
	{
		$Input = Input::getInstance();
		$Input->filter('addslashes');
		//设置查询条件
		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('einfos_id',array('EQ',$Input->get('einfos_id')));
		//获取要查看的信息
		$Info = D('Einfoservices');
		$I = $Info->where($conditions)->xfind();
		unset($conditions);
		//获取企业信息
		//设置条件
		$conditions = new HashMap();
		$conditions->put('enter_id',array('EQ',$Input->get('enter_id')));
		
		$Enterprise = D('Enterprise');
		$Enter = $Enterprise->where($conditions)->find();
		//组成模板 xxx@Index:Show
    	$UserTpl = $Enter['templates'] . '@Einfoservices:DS';
    	
		//To tpl
		$this->assign('Enterprise',$Enter);
		$this->assign('enter_id',$Input->get('enter_id'));
		$this->assign('Config',$this->Config);
		$this->assign('Info',$I);
		$this->display($UserTpl);
	}
	/**
	 * 普通用户创建发送求职信息
	 */
	public function UserCreateJobs()
	{
		EasyACL('Einfoservices','UserCreateJobs',$_SESSION);
		$this->display();
	}
	/**
	 * 获取信息分类
	 */
	public function UserGetClass()
	{
		EasyACL('Einfoservices','UserGetClass',$_SESSION);
		$Input = Input::getInstance();
		$Input->filter('addslashes');

		import('ORG.Util.HashMap');
		$conditions = new HashMap();
		$conditions->put('cid',array('EQ',$Input->get('id')));
		$Class = D('Einfoc');
		$C = $Class->where($conditions)->findall();
		//dump($C);
		$str="<select name='id' id='professionalid'> <option value=".$Input->get('id').">请选择子分类</option>"; 
		foreach ($C as $s) {
			$str.='<option value="'.$s["id"].'">'.$s["name"].'</option>';
		}
		$str.='</select>';
		echo $str;
	}
	/**
	 * 按条件进行查询
	 * 供求信息
	 */
    public function UserIndex()
    {
    	EasyACL('Einfoservices','UserIndex',$_SESSION);
    	import('ORG.Util.HashMap');
    	$conditions = new HashMap();
    	$conditions->put('enter_id',array('EQ',$_SESSION['enter_id']));
    	
    	$Info = D('Einfoservices');
    	$count = $Info->count($conditions,'einfos_id');
    	$listRows = 15;
    	$fields = 'einfos_id,id,einfos_audit,title,created';
    	import('ORG.Util.Page');
    	$p = new Page($count,$listRows);
    	$list = $Info->xfindall($conditions,$fields,'einfos_id desc',$p->firstRow .','.$p->listRows);
    	$page = $p->show();
    	
    	//To Templates
    	$this->assign('Infos',$list);
    	$this->assign('page',$page);
    	$this->assign('Config',$this->Config);
    	$this->display();
    }
    
    /**
     * 创建信息
     */
    public function UserCreate()
    {
    	EasyACL('Einfoservices','UserCreate',$_SESSION);
    	if ($this->isPost()) {
    		$Input = Input::getInstance();
    		$Input->filter('addslashes');
    		
    		$Info = D('Einfoservices');
    		$Info->id = $Input->post('id');
    		$Info->cid = $Input->post('cid');
    		$Info->enter_id = $_SESSION['enter_id'];
    		if ($Input->post('title')) {
    			$Info->title = $Input->post('title');
    		}
    		$Info->content = $Input->post('content');
    		$time = time();
    		$Info->created = $time;
    		$Info->updated = $time;
    		if ($Info->add()) {
    			$this->redirect('UserCreate','Einfoservices');
    		} else {
    			$this->error('尝试创建信息失败');
    		}
    	}
    	
		//设置查询条件
		$conditions = array();
		$conditions['state'] = 1;
		$Ex = D('Einfoc');
		$re = $Ex->field('id,cid,name')->where('cid=0')->order('id asc')->xfindAll($conditions);
		
		$this->assign('re',$re);
    	$this->display();
    }
    
    /**
     * 修改信息
     */
    public function UserUpdate()
    {
    	EasyACL('Einfoservices','UserUpdate',$_SESSION);
    	$Info = D('Einfoservices');
    	
    	import('ORG.Util.HashMap');
    	$conditions = new HashMap();
    	
    	$Input = Input::getInstance();
    	$Input->filter('addslashes');
    	
    	//POST
    	if ($this->isPost()) {
    		$conditions->put('einfos_id',array('EQ',$Input->post('einfos_id')));
    		$Info->where($conditions)->find();
    		$Info->id = $Input->post('id');
    		$Info->cid = $Input->post('cid');
    		$Info->title = $Input->post('title');
    		$Info->content = $Input->post('content');
    		$Info->updated = $Input->post('updated');
    		if ($Info->save()) {
    			$this->redirect('UserIndex','Einfoservices');
    		} else {
    			return $this->error('尝试修改信息内容失败');
    		}
    	}
    	//获取要修改的信息
    	$conditions->put('einfos_id',array('EQ',$Input->get('einfos_id')));
    	$InfoContent = $Info->where($conditions)->find();
    	
		//设置查询条件
		$conditions = array();
		$conditions['state'] = 1;
		$Ex = D('Einfoc');
		$re = $Ex->field('id,cid,name')->where('cid=0')->order('id asc')->xfindAll($conditions);
		
		//To templates
		$this->assign('re',$re);
    	$this->assign('Info',$InfoContent);
    	$this->display();
    }
    
    /**
     * 删除数据
     */
    public function UserDel($id)
    {
    	EasyACL('Einfoservices','UserDel',$_SESSION);
    	$Info = D('Einfoservices');
    	if ($Info->deleteById($id)) {
    		return TRUE;
    	} else {
    		return FALSE;
    	}
    }
    
    /**
     * 批量删除数据
     */
    public function UserDels()
    {
    	EasyACL('Einfoservices','UserDels',$_SESSION);
    	//POST
    	if ($this->isPost()) {
    		$Einfos = $_POST['einfos_id'];
    		$Error = '';
    		foreach ($Einfos as $id) {
    			if (!$this->UserDel($id)) {
    				$Error .= '删除编号为'.$id.'信息失败<br />';
    			}
    		}
    		if (empty($Error)) {
    			$this->redirect('UserIndex','Einfoservices');
    		} else {
    			$this->error($Error);
    		}
    	}
    	
    	//GET
    	if ($this->isGet()) {
    		$Input = Input::getInstance();
    		$Input->filter('addslashes');
    		if ($this->UserDel($Input->get('einfos_id'))) {
    			$this->redirect('UserIndex','Einfoservices');
    		} else {
    			$this->error('尝试删除失败!');
    		}
    	}
    }
}
?>